public class SierpinskiTriangle extends SceneGraphNode {
	
	public SierpinskiTriangle(int depth) {
		this(depth, true);
	}
	
	public SierpinskiTriangle(int depth, boolean pickable) {
		super(pickable);
		this.scale = 2;
		addChild(create(depth));
	}
	
	private static SceneGraphNode create(int depth) {
		if (depth <= 1) {
			return (new Triangle(1f, false)).renderable;
		}
		
		SceneGraphNode parent = new SceneGraphNode(false);
		SceneGraphNode child = SierpinskiTriangle.create(depth-1);
		child.scale = .5f;
		child.translateX = -.25f;
		child.translateY = -Triangle.SIN_60 / 6;
		parent.addChild(child);
		child = SierpinskiTriangle.create(depth-1);
		child.scale = .5f;
		child.translateY = Triangle.SIN_60 / 3;
		parent.addChild(child);
		child = SierpinskiTriangle.create(depth-1);
		child.scale = .5f;
		child.translateX = .25f;
		child.translateY = -Triangle.SIN_60 / 6;
		parent.addChild(child);
		
		return parent;
	}
}
